package com.ynhenc.pta.routeRank;

import java.awt.*;

import com.ynhenc.comm.util.ColorUtil;

public interface TransitType  extends KmlInterface  {
	
	public double getCarbonEmissonCoeff();
	public double getDirectConnectCoeff();
	public double getSpeedAverage_MeterPerSec();
	
	public String getKmlStyleName();
	public String getTransitName();
	
	public int getCode();
	
	TransitType WALK = new TransitTypeImpl( 100, "WALK" , 0 , Color.YELLOW , -1, 4 ) ;
	TransitType BIKE = new TransitTypeImpl( 200, "BIKE", 0 , Color.YELLOW, -1 , 12 ) ;
	TransitType SUBWAY = new TransitTypeImpl( 300, "SUBWAY", 0.000384 , Color.RED, -1 , 60 ) ;
	TransitType BUS = new TransitTypeImpl( 400, "BUS", 0.0156 , Color.RED, -1 , 60 ) ;
	TransitType AUTOMOBILE = new TransitTypeImpl( 500, "AUTOMOBILE", 0.21 , Color.RED, -1 , 80 ) ; 

	 class TransitTypeImpl implements TransitType {

		private TransitTypeImpl( int code, String name, double carbonEmissionCoefficient, Color lineColor , double directConnectCoeff , double speed_KmPerHour ) {
			this.code = code;
			this.name = name;
			this.carbonEmissionCoefficient = carbonEmissionCoefficient;
			this.lineColor = lineColor; 
			this.directConnectCoeff = directConnectCoeff;
			
			this.speed_MeterPerSec = (5.0/18.0)*speed_KmPerHour ;
			
		}
		
		public double getSpeedAverage_MeterPerSec() {
			return this.speed_MeterPerSec;
		}
		
		public double getDirectConnectCoeff() {
			return this.directConnectCoeff;
		}
		
		public String toString() {
			return "" + this.name;
		}

		public String getKmlStyleName() {
			return "transitType_" + this.name;
		}
		
		public void toKml( StringBuffer buff ) {  
			String styleIdTxt = this.getKmlStyleName() ;
			String lineWidthTxt = "3.5";
			String lineColorTxt = ColorUtil.toKmlColor( this.getLineColor(), -1 ) ;
			
			String tag = "<Style id=\"styleIdVal\"><LineStyle><width>lineWidthVal</width><color>lineColorVal</color></LineStyle></Style>"; 
			
			tag = tag.replaceAll( "styleIdVal", styleIdTxt );
			tag = tag.replaceAll( "lineWidthVal", lineWidthTxt );
			tag = tag.replaceAll( "lineColorVal", lineColorTxt );
			
			buff.append( tag );
		}
		
		public double getCarbonEmissonCoeff() {
			return this.carbonEmissionCoefficient;
		}
		
		public Color getLineColor () {
			return this.lineColor;
		}
		
		public String getTransitName() {
			return this.name;
		}
		
		public int getCode() {
			return this.code;
		}

		private String name;
		private int code;
		private double carbonEmissionCoefficient;
		private double directConnectCoeff;
		private double speed_MeterPerSec;
		private Color lineColor = Color.BLACK;
	}
}
